import RuleClass,DataClass
import ReachMongo, data
import json
DATA = DataClass.Data()
rb = RuleClass.RuleBox()
FSM = []


def rulebuffer():
    for rf in ReachMongo.FetchRules():
        ru = RuleClass.Rule(rf)
        rb.add(ru)
        
def FSMinit():
    global FSM
    for r in rb.list:
        FSM.append(r.thisFSM)
        print FSM
        
def FSMupdate(row, grade, status):
    global FSM
    FSM[row][grade] = status

def FSMcheck():
    for i in xrange(len(FSM)):
        if FSM[i].count(0) == 0:
            print str(i) + 'FSMchecked!!'
def checkstack():
    for i in xrange(len(rb.list)):

def check(rule):
    
    
def databuffer():
    global DATA
    if len(DATA.list) == 0:
        DATA.list = json.loads(data.getData())
        print DATA.count()
        return True
    da = json.loads(data.getData())
    DATA.refresh(da)
    print DATA.list
    
if __name__ == "__main__":
    #databuffer()
    rulebuffer()
    FSMinit()
    
    
    
        
